package com.zxhhyj.storm.database.sqlite

import androidx.annotation.IntRange
import com.zxhhyj.storm.schema.DataType

interface SQLiteStatement : AutoCloseable {

    fun bindBlob(@IntRange(from = 1) index: Int, value: ByteArray)

    fun bindDouble(@IntRange(from = 1) index: Int, value: Double)

    fun bindFloat(@IntRange(from = 1) index: Int, value: Float) {
        bindDouble(index, value.toDouble())
    }

    fun bindLong(@IntRange(from = 1) index: Int, value: Long)

    fun bindInt(@IntRange(from = 1) index: Int, value: Int) {
        bindLong(index, value.toLong())
    }

    fun bindBoolean(@IntRange(from = 1) index: Int, value: Boolean) {
        bindLong(index, if (value) 1L else 0L)
    }

    fun bindText(@IntRange(from = 1) index: Int, value: String)

    fun bindNull(@IntRange(from = 1) index: Int)

    fun getBlob(@IntRange(from = 0) index: Int): ByteArray

    fun getDouble(@IntRange(from = 0) index: Int): Double

    fun getFloat(@IntRange(from = 0) index: Int): Float {
        return getDouble(index).toFloat()
    }

    fun getLong(@IntRange(from = 0) index: Int): Long

    fun getInt(@IntRange(from = 0) index: Int): Int {
        return getLong(index).toInt()
    }

    fun getBoolean(@IntRange(from = 0) index: Int): Boolean {
        return getLong(index) != 0L
    }

    fun getText(@IntRange(from = 0) index: Int): String

    fun isNull(@IntRange(from = 0) index: Int): Boolean

    fun getColumnCount(): Int

    fun getColumnName(@IntRange(from = 0) index: Int): String

    fun getColumnNames(): List<String> {
        return List(getColumnCount()) { i -> getColumnName(i) }
    }

    fun getColumnType(@IntRange(from = 0) index: Int): DataType

    fun step(): Boolean

    fun reset()

    fun clearBindings()

    override fun close()
}
